<html lang="en">
<head>
    <title>日报管理</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script type="text/javascript" src="/js/ckeditor/ckeditor/ckeditor.js"></script>
    <script>
        $(function () {
            //富文本框编辑器
            var ck = CKEDITOR.replace('content', {
                filebrowserBrowseUrl: '/装作有服务器',
                filebrowserUploadUrl: '/images/upload.do'
            });


            $(".inputBtn").click(function () {

                //重置表单
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if (json) {
                    $("#editForm input[name='title']").val(json.title)
                    $("#editForm input[name='subTitle']").val(json.subTitle)
                    $("#editForm input[name='coverUrl']").val(json.coverUrl)
                    $("#coverUrl").attr("src", json.coverUrl);
                    $("#editForm select[name='state']").val(json.state)
                    $("#editForm input[name='id']").val(json.id)
                    $("#editForm select[name='place.id']").val(json.placeId);


                    //内容的回显,因为内容传输太大,所有通过查询,而不通过json查询
                    $.get("/daily/getContentBydailyId.do", {dailyId: json.id}, function (data) {
                        ck.setData(data.content);
                    })
                }
                $("#editModal").modal("show");

            })
            //修改操作
            $(".saveBtn").click(function () {
                var content = ck.getData();
                console.log(content);
                $("#content").html(content);

                //提交表单之前判断是否选中推荐的类型,如果不等于-1,在提交表单,否则不提交表单
                $('#editForm').ajaxSubmit({

                beforeSubmit:function (params) {
                    var type = $("#editForm select[name='state']");
                    if (type.val() == -1) {
                        $.messager.alert("温馨提示", "请选择推荐的类型")
                        return false;
                    }
                }
            ,
                success:function (data) {
                    if (data.success) {
                        window.location.reload();
                    } else {
                        $.messager.alert("温馨提示", e.msg);
                    }
                }
            })
            })


        })
    </script>
    <style>
        #contentModal img {
            width: 100%; /*模态框中出现的图片大小占模态框的多少*/
        }

        #contentModal .modal-body {
            max-height: 600px;
            overflow-y: auto; /*模态框的滑动,*/
        }
    </style>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="daily">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">全部日报管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/daily/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a href="javascript:;" id="btn_query" class="btn btn-info inputBtn"><span
                        class="glyphicon glyphicon-plus"></span> 添加</a>
            </form>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>封面</th>
                    <th>副标题</th>
                    <th>创建时间</th>
                    <th>推荐头条时间</th>
                    <th>日报地区</th>
                    <th>状态</th>
                    <th>编辑</th>
                </tr>
                </thead>
                <#list result.list as entity >
                     <tr>
                         <td>${entity.title!}</td>
                         <td><img src="${entity.coverUrl!}" width="30px;"></td>
                         <td>${(entity.subTitle)!}</td>
                         <td>${(entity.creatTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                         <td>${(entity.releaseTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                         <td>${(entity.place.name)!}</td>
                         <td>${entity.stateDisplay!}</td>
                         <td>
                             <a href="javascript:;" class="btn inputBtn" data-json='${entity.jsonString}'>修改</a>
                         </td>
                     </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>












<#--查看文章的内容-->
<div id="contentModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">文章内容</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">确定</a>
            </div>
        </div>
    </div>
</div>

<#--推荐游记编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">推荐游记编辑</h4>
            </div>
            <div class="modal-body">
            <#--提交修改图片的时候,会有file. spring会将普通的input封装到对象中,file控件不能封装-->
                <form class="form-horizontal" action="/daily/saveOrUpdate.do" method="post"
                      enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" value="" placeholder="请输入标题名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px;">
                            <input type="file" name="file">
                        <#--如果上面的file没有选中,会为空值,updata时,还会 更新,
                            解决
                        -->
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle" value="" placeholder="请输入副标题名称">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">日报地区：</label>
                        <div class="col-sm-6">
                            <select name="place.id" class="form-control">
                                <#list regions as r>
                                    <option value="${r.id!}">${r.name!}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日报状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="-1">--请选择--</option>
                                <option value="1">头条</option>
                                <option value="0">普通</option>
                            </select>
                        </div>
                    </div>
                <#--富文本编辑框-->
                    <textarea name="content.content" id="content" rows="10" cols="80">

            </textarea>

                </form>
            </div>


            <div class="modal-footer">
                <button type="submit" class="btn btn-primary saveBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
